﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PhatPhucLoc.dao;
using PhatPhucLoc.model;

namespace PhatPhucLoc.view
{
    public partial class FormKhachHang : Form
    {
        public FormKhachHang()
        {
            InitializeComponent();
            FormKhachMuaHangLoad();
        }

        private void tsbThem_Click(object sender, EventArgs e)
        {
            FormKhachHang formKhachHang = this;
            formThemKhachHang formThemKhachHang = new formThemKhachHang(ref formKhachHang);
            formThemKhachHang.ShowDialog();
        }

        public void FormKhachMuaHangLoad()
        {
            DataTable dt = KhachHangDAO.KhachHang_GetAll();
            dgvKhachHang.DataSource = dt;

        }

        private void dgvKhachHang_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            FormKhachHang formKhachHang = this;

            KhachHangModel khachHangModel = new KhachHangModel();
            khachHangModel.Id = dgvKhachHang.CurrentRow.Cells["Id"].Value.ToString();
            khachHangModel.MaSoThue = dgvKhachHang.CurrentRow.Cells["maSoThue"].Value.ToString();
            khachHangModel.NganHang = dgvKhachHang.CurrentRow.Cells["nganHang"].Value.ToString();
            khachHangModel.SoTaiKhoan = dgvKhachHang.CurrentRow.Cells["soTaiKhoan"].Value.ToString();
            khachHangModel.Tel = dgvKhachHang.CurrentRow.Cells["tel"].Value.ToString();
            khachHangModel.Ten = dgvKhachHang.CurrentRow.Cells["tenKH"].Value.ToString();
            khachHangModel.Fax = dgvKhachHang.CurrentRow.Cells["fax"].Value.ToString();
            khachHangModel.DiaChi = dgvKhachHang.CurrentRow.Cells["diaChi"].Value.ToString();
            khachHangModel.Email = dgvKhachHang.CurrentRow.Cells["email"].Value.ToString();
            khachHangModel.GhiChu = dgvKhachHang.CurrentRow.Cells["ghiChu"].Value.ToString();

            formThemKhachHang formThemKhachHang = new formThemKhachHang(khachHangModel, ref formKhachHang);
            formThemKhachHang.ShowDialog();
        }

        private void formKhachHang_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.formKhachHang_KeyDown);
        }

        private void formKhachHang_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                tsbThem.PerformClick();
            }
            else if (e.KeyCode == Keys.F4)
            {
                tsbThoat.PerformClick();
            }
        }

        private void tsbThoat_Click(object sender, EventArgs e)
        {

        }



    }
}
